Skip to content

Implementation: #[feature(sync_nonpoison)], #[feature(nonpoison_mutex)] #144022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

connortsui20
Copy link
Contributor

@connortsui20 connortsui20 commented Jul 16, 2025

Continuation of #134663

Tracking Issue: #134645

This PR implements a new sync/nonpoison module, as well as the nonpoison variant of the Mutex lock.

There are 2 main changes here, the first is the new nonpoison::mutex module, and the second is the mutex integration tests.

For the nonpoison::mutex module, I did my best to align it with the current state of the poison::mutex module. This means that several unstable features (mapped_lock_guards, lock_value_accessors, and mutex_data_ptr) are also in the new nonpoison::mutex module, under their respective feature gates. Everything else in that file is under the correct feature gate (#[unstable(feature = "nonpoison_mutex", issue = "134645")]).

Everything in the nonpoison::mutex file is essentially identical in spirit, as we are simply removing the error case from the original poison::mutex.

The second big change is in the integration tests. I created a macro called that allows us to duplicate tests that are "generic" over the different mutex types, in that the poison mutex is always unwrapped.

I think that there is an argument against doing this, as it can make the tests a bit harder to understand (and language server capabilities are weaker within macros), but I think the benefit of code deduplication here is worth it. Note that it is definitely possible to generalize this (with a few tweaks) to testing the other nonpoison locks when they eventually get implemented, but I'll leave that for a later discussion.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 16, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@connortsui20 connortsui20 force-pushed the sync_nonpoison branch 2 times, most recently from e130930 to 804d305 Compare July 18, 2025 08:58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: since this is a large file, it might be good to compare this directly with the poison::mutex module.

(for copy paste)

delta library/std/src/sync/poison/mutex.rs library/std/src/sync/nonpoison/mutex.rs
diff library/std/src/sync/poison/mutex.rs library/std/src/sync/nonpoison/mutex.rs

Copy link
Contributor Author

@connortsui20 connortsui20 Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git diff here is somewhat unfortunate, as I had to reorder the tests for things to make sense. All of the "duplicated" tests here are taken from the existing tests in the file, so there is technically nothing new here other than the macro.

I would ideally like to write some more tests (testing more panic behavior in nonpoison, better tests for the replace drop behavior), but this is already quite a large PR. (Also the panic behavior is already in the doc test)

@connortsui20 connortsui20 marked this pull request as ready for review July 18, 2025 09:23
@rustbot
Copy link
Collaborator

rustbot commented Jul 18, 2025

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 18, 2025
@tgross35
Copy link
Contributor

r? tgross35

@rustbot rustbot assigned tgross35 and unassigned thomcc Jul 18, 2025
@connortsui20 connortsui20 force-pushed the sync_nonpoison branch 3 times, most recently from c5133bf to f633b62 Compare July 21, 2025 11:45
Aandreba and others added 4 commits July 21, 2025 13:46
Commits squashed from pull 134663.
This commit brings the `mutex.rs` file more in line with the current
`poison/mutex.rs` file.

Additionally, it ensures that all items are marked with
`#[unstable(feature = "nonpoison_mutex", issue = "134645")]`. Some
features that are currently unstable on nightly also have the
"nonpoison_mutex" feature, but they have their correct feature gates
commented out above.

Not all of the current nightly features are implemented here, and that
will happen in a later commit.

Note that this commit will likely not pass CI.
This commit moves the duplicating test macro for poison and nonpoison
locks into the parent module. Since it is generic for all locks (either
it calls `unwrap` or it doesn't), we can use it for all poison/nonpoison
lock tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants